package com.ljw.Utils;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

import java.io.IOException;
import java.util.Properties;

/**
 * Created by admin on 2017/11/5.
 */
public  class HbaseUtil {

   private  static Properties  properties=new Properties();
   static {
       try {
           properties.load(HbaseUtil.class.getClassLoader().getResourceAsStream("hbase.properties"));

       } catch (IOException e) {
           e.printStackTrace();
       }

   }
  private  static Configuration configuration= HBaseConfiguration.create();
   private static Admin admin=null;
   private static Connection connection=null;
   public static  Configuration getConfiguration(){
       configuration.set("hbase.rootdir",properties.getProperty("hbase.rootdir"));
       configuration.set("hbase.cluster.distributed",properties.getProperty("hbase.cluster.distributed"));
       configuration.set("hbase.zookeeper.quorum",properties.getProperty("hbase.zookeeper.quorum"));
       return configuration;
   }
   public static Connection getConnection(){
       configuration=getConfiguration();
       try {
           connection= ConnectionFactory.createConnection(configuration);

       } catch (IOException e) {
           e.printStackTrace();
       }
     return connection;
   }
   public static Admin getAdmin(){

           connection=getConnection();
       try {
           admin=connection.getAdmin();
       } catch (IOException e) {
           e.printStackTrace();
       }

       return admin;
   }




}
